/*     */ package com.umeng.analytics;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.content.SharedPreferences;
/*     */ import com.umeng.common.Log;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.StringWriter;
/*     */ import java.net.URLEncoder;
/*     */ import org.json.JSONException;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public final class j
/*     */ {
/*     */   private static final String c = "cache_version";
/*     */   private static final String d = "error";
/*     */   private static final String e = "mobclick_agent_user_";
/*     */   private static final String f = "mobclick_agent_online_setting_";
/*     */   private static final String g = "mobclick_agent_header_";
/*     */   private static final String h = "mobclick_agent_update_";
/*     */   private static final String i = "mobclick_agent_state_";
/*     */   private static final String j = "mobclick_agent_cached_";
/* 114 */   static long a = 1209600000L;
/* 115 */   static long b = 2097152L;
/*     */ 
/*     */   static SharedPreferences a(Context paramContext)
/*     */   {
/*  40 */     return paramContext.getSharedPreferences("mobclick_agent_user_" + paramContext.getPackageName(), 0);
/*     */   }
/*     */ 
/*     */   public static SharedPreferences b(Context paramContext) {
/*  44 */     return paramContext.getSharedPreferences("mobclick_agent_online_setting_" + paramContext.getPackageName(), 0);
/*     */   }
/*     */ 
/*     */   public static SharedPreferences c(Context paramContext) {
/*  48 */     return paramContext.getSharedPreferences("mobclick_agent_header_" + paramContext.getPackageName(), 0);
/*     */   }
/*     */ 
/*     */   static SharedPreferences d(Context paramContext) {
/*  52 */     return paramContext.getSharedPreferences("mobclick_agent_update_" + paramContext.getPackageName(), 0);
/*     */   }
/*     */ 
/*     */   public static SharedPreferences e(Context paramContext) {
/*  56 */     return paramContext.getSharedPreferences("mobclick_agent_state_" + paramContext.getPackageName(), 0);
/*     */   }
/*     */ 
/*     */   static String f(Context paramContext) {
/*  60 */     return "mobclick_agent_header_" + paramContext.getPackageName();
/*     */   }
/*     */ 
/*     */   static String g(Context paramContext) {
/*  64 */     return "mobclick_agent_cached_" + paramContext.getPackageName();
/*     */   }
/*     */ 
/*     */   static JSONObject h(Context paramContext) {
/*  68 */     JSONObject localJSONObject = new JSONObject();
/*  69 */     SharedPreferences localSharedPreferences = a(paramContext);
/*     */     try {
/*  71 */       if (localSharedPreferences.getInt("gender", -1) != -1) {
/*  72 */         localJSONObject.put("sex", localSharedPreferences.getInt("gender", -1));
/*     */       }
/*     */ 
/*  75 */       if (localSharedPreferences.getInt("age", -1) != -1) {
/*  76 */         localJSONObject.put("age", localSharedPreferences.getInt("age", -1));
/*     */       }
/*     */ 
/*  79 */       if (!"".equals(localSharedPreferences.getString("user_id", ""))) {
/*  80 */         localJSONObject.put("id", localSharedPreferences.getString("user_id", ""));
/*     */       }
/*     */ 
/*  83 */       if (!"".equals(localSharedPreferences.getString("id_source", ""))) {
/*  84 */         localJSONObject.put("url", URLEncoder.encode(localSharedPreferences.getString("id_source", ""), "UTF-8"));
/*     */       }
/*     */ 
/*  87 */       if (localJSONObject.length() > 0)
/*  88 */         return localJSONObject;
/*     */     } catch (Exception localException) {
/*  90 */       localException.printStackTrace();
/*     */     }
/*  92 */     return null;
/*     */   }
/*     */ 
/*     */   public static int[] i(Context paramContext)
/*     */   {
/* 101 */     SharedPreferences localSharedPreferences = b(paramContext);
/* 102 */     int[] arrayOfInt = new int[2];
/* 103 */     if (localSharedPreferences.getInt("umeng_net_report_policy", -1) != -1) {
/* 104 */       arrayOfInt[0] = localSharedPreferences.getInt("umeng_net_report_policy", 1);
/* 105 */       arrayOfInt[1] = ((int)localSharedPreferences.getLong("umeng_net_report_interval", g.h));
/*     */     } else {
/* 107 */       arrayOfInt[0] = localSharedPreferences.getInt("umeng_local_report_policy", 1);
/* 108 */       arrayOfInt[1] = ((int)localSharedPreferences.getLong("umeng_local_report_interval", g.h));
/*     */     }
/*     */ 
/* 111 */     return arrayOfInt;
/*     */   }
/*     */ 
/*     */   static boolean a(File paramFile)
/*     */   {
/* 118 */     long l = paramFile.length();
/*     */ 
/* 120 */     if ((paramFile.exists()) && (l > b)) {
/* 121 */       return true;
/*     */     }
/*     */ 
/* 124 */     return false;
/*     */   }
/*     */ 
/*     */   static JSONObject a(Context paramContext, String paramString) {
/* 128 */     String str1 = g(paramContext);
/*     */     try
/*     */     {
/* 131 */       File localFile = new File(paramContext.getFilesDir(), str1);
/* 132 */       if (a(localFile)) {
/* 133 */         localFile.delete();
/* 134 */         return null;
/*     */       }
/*     */ 
/* 137 */       FileInputStream localFileInputStream = paramContext.openFileInput(str1);
/* 138 */       String str2 = null;
/*     */       try
/*     */       {
/* 141 */         str2 = a(localFileInputStream);
/*     */       } catch (Exception localException) {
/* 143 */         localException.printStackTrace();
/* 144 */         return null;
/*     */       } finally {
/* 146 */         localFileInputStream.close();
/*     */       }
/*     */       try
/*     */       {
/* 150 */         JSONObject localJSONObject = new JSONObject(str2);
/*     */ 
/* 152 */         if (!localJSONObject.optString("cache_version").equals(paramString)) {
/* 153 */           localJSONObject.remove("error");
/*     */         }
/*     */ 
/* 156 */         localJSONObject.remove("cache_version");
/*     */ 
/* 158 */         if (localJSONObject.length() == 0) return null;
/*     */ 
/* 160 */         return localJSONObject;
/*     */       }
/*     */       catch (JSONException localJSONException) {
/* 163 */         j(paramContext);
/* 164 */         localJSONException.printStackTrace();
/* 165 */         return null;
/*     */       }
/*     */     }
/*     */     catch (FileNotFoundException localFileNotFoundException)
/*     */     {
/* 170 */       return null;
/*     */     }
/*     */     catch (IOException localIOException) {
/* 173 */       return null; } catch (Throwable localThrowable) {
/*     */     }
/* 175 */     return null;
/*     */   }
/*     */ 
/*     */   static String a(InputStream paramInputStream) throws IOException
/*     */   {
/* 180 */     InputStreamReader localInputStreamReader = new InputStreamReader(paramInputStream);
/*     */ 
/* 182 */     char[] arrayOfChar = new char[1024];
/* 183 */     int k = 0;
/*     */ 
/* 185 */     StringWriter localStringWriter = new StringWriter();
/*     */ 
/* 187 */     while (-1 != (k = localInputStreamReader.read(arrayOfChar))) {
/* 188 */       localStringWriter.write(arrayOfChar, 0, k);
/*     */     }
/*     */ 
/* 191 */     return localStringWriter.toString();
/*     */   }
/*     */ 
/*     */   static void a(Context paramContext, JSONObject paramJSONObject, String paramString) throws Exception {
/* 195 */     if (paramJSONObject == null) return;
/*     */ 
/* 197 */     String str = g(paramContext);
/*     */ 
/* 199 */     FileOutputStream localFileOutputStream = null;
/*     */ 
/* 201 */     paramJSONObject.put("cache_version", paramString);
/* 202 */     localFileOutputStream = paramContext.openFileOutput(str, 0);
/* 203 */     localFileOutputStream.write(paramJSONObject.toString().getBytes());
/* 204 */     localFileOutputStream.flush();
/* 205 */     localFileOutputStream.close();
/*     */ 
/* 207 */     Log.c("MobclickAgent", "cache buffer success");
/*     */   }
/*     */ 
/*     */   static void a(Context paramContext, com.umeng.analytics.a.g paramg, String paramString) {
/* 211 */     if (paramg == null) return;
/*     */     try
/*     */     {
/* 214 */       JSONObject localJSONObject = new JSONObject();
/* 215 */       paramg.b(localJSONObject);
/*     */ 
/* 217 */       a(paramContext, localJSONObject, paramString);
/*     */     } catch (Exception localException) {
/* 219 */       Log.b("MobclickAgent", "cache message error", localException);
/* 220 */       return;
/*     */     }
/*     */   }
/*     */ 
/*     */   static void b(Context paramContext, JSONObject paramJSONObject, String paramString) {
/* 225 */     if (paramJSONObject == null) return;
/*     */ 
/* 227 */     JSONObject localJSONObject = null;
/*     */     try {
/* 229 */       localJSONObject = paramJSONObject.optJSONObject("body");
/* 230 */       a(paramContext, localJSONObject, paramString);
/*     */     } catch (Exception localException) {
/* 232 */       Log.b("MobclickAgent", "cache message error", localException);
/* 233 */       return;
/*     */     }
/*     */   }
/*     */ 
/*     */   static void j(Context paramContext) {
/* 238 */     paramContext.deleteFile(f(paramContext));
/* 239 */     paramContext.deleteFile(g(paramContext));
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.analytics.j
 * JD-Core Version:    0.6.2
 */